package cbr.resilienceManager.qmul.gemom;

import java.awt.Frame;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTabbedPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JPanel;
import javax.swing.ListSelectionModel;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.BorderLayout;
import javax.swing.JButton;
import javax.swing.JTree;
import javax.swing.table.DefaultTableModel;
import javax.swing.tree.DefaultMutableTreeNode;

import java.awt.Dialog;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JTextField;

import resilienceManager.qmul.gemom.Gbroker;
import resilienceManager.qmul.gemom.NSitem;
import resilienceManager.qmul.gemom.XMLfilter;
import resilienceManager.qmul.gemom.scParser;
 

import ac.uk.qmul.gemom.scenario.Publisher;
import ac.uk.qmul.gemom.scenario.AutoSubscriber;
import ac.uk.qmul.gemom.scenario.DemoResource;
import ac.uk.qmul.gemom.scenario.Subscription;
import ac.uk.qmul.gemom.scenario.ScenarioFileParser;
import ac.uk.qmul.gemom.scenario.TextFile;

import inl.resilienceManager.qmul.gemom.gTable;

/**
 * 
 * The control frame for the Resilience Manager in online response mode.
 * 
 * The online response mode of the Resilience Manager monitors the operation
 * of the GEMOM broker system indirectly by hearing updates from Anomaly Detectors
 * and Overlay Managers. If broker failure signals are heard from the GEMOM Overlay
 * Manager, the Resilience Manager(online response mode)either retrieves previously
 * calculated resilience solutions (Case-based Reasoning)or calculates a solution
 * based on the current system failure situation. The generated solution is then
 * fed to the GEMOM Overlay Manager where the execution of the solution is solely
 * dependent on.
 * 
 * COPYRIGHT DISCLAIMER
 * Synopsis: All the source codes presented in this document are intellectual
 * properties of Queen Mary, University of London.
 * 
 * @year 2010
 * @author Peng Jiang, John Bigham, Jiayi Wu, Jinfu Wang------------QMUL
 * @version 1.0 
 */

public class CbrResilienceManager extends JFrame {

	private static final long serialVersionUID = 1L;
	private JTabbedPane jTabbedPane = null;
	private JScrollPane jScrollPane = null;
	private JTable jTable = null;
	private JPanel jPanel = null; 
	private JPanel jPanelCbrResilience = null;
	private JPanel jPanelQuerySender = null;

	private CbrServiceClient cbrServiceClient; 
	
	private CbrQuerySender testQueryPublisher;
	  
	
	/*
	 * This is the default constructor
	 */
	public CbrResilienceManager() {
		super("Real time GEMOM Resilience Service");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setLayout(new BorderLayout());
		//this.setSize(800, 450);

		this.setBounds(10, 10, 1200, 600);
		this.add(getJTabbedPane(), BorderLayout.CENTER);
		
		Dimension scr = Toolkit.getDefaultToolkit().getScreenSize(); 
		Dimension frm = this.getSize(); 
		setLocation( (scr.width - frm.width) / 2, 
				(scr.height - frm.height) / 2 - 18); 
		
	}

	/**
	 * This method initializes jTabbedPane	
	 * 	
	 * @return javax.swing.JTabbedPane	
	 */
	private JTabbedPane getJTabbedPane() {
		if (jTabbedPane == null) {
			jTabbedPane = new JTabbedPane();
			 
			jTabbedPane.addTab("CBR Resilience Service", null, getJPanelCbrResilience(), null);
			jTabbedPane.addTab("Resilience Query Sender", null, getJPanelQuerySender(), null); 
		}
		return jTabbedPane;
	}

	  
	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelCbrResilience() {
		if (jPanelCbrResilience == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(1);
			jPanelCbrResilience = new JPanel();
			jPanelCbrResilience.setLayout(gridLayout);
			     
			jPanelCbrResilience.add(this.cbrServiceClient = new CbrServiceClient(), BorderLayout.CENTER);
			 
		}
		return jPanelCbrResilience;
	}
	       
	private JPanel getJPanelQuerySender() {
		if (jPanelQuerySender == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(1);
			jPanelQuerySender = new JPanel();
			jPanelQuerySender.setLayout(gridLayout);
			      
			jPanelQuerySender.add(this.testQueryPublisher = new CbrQuerySender(cbrServiceClient), BorderLayout.CENTER);
		}
		return jPanelQuerySender;
	}

}   


